/**
 * Created by 55456 on 2016/4/8.
 */
var sequelizex = require("../lib/sequelizex");
var shortTypes = sequelizex.DataTypes;
module.exports = (sequelize,DataTypes) => {
    var User = sequelize.define("User",{
        mobile: shortTypes.Phone(),

        password : shortTypes.String(),

        avatar : shortTypes.Url(),

        sign : shortTypes.String(null,true),

        userName : shortTypes.String(),

        //todo:后台加盐
        token : shortTypes.String(),
        // 2 : 没有性别
        sex : shortTypes.Int(2),

        noticeEnable : shortTypes.Int(1),

        followingEnable : shortTypes.Int(1),

        followerEnable : shortTypes.Int(1),

        aboutNotice : shortTypes.Int(1),

        updateNotice : shortTypes.Int(1)
    },{
        timestamps:false,
        associate:function(models){
            models.User.belongsToMany(models.Story,{through : "UserStory"});
            models.User.hasMany(models.Story,{as:"MyStory",foreignKey:"AuthorID"});
            models.User.hasMany(models.Comment);
            models.User.belongsToMany(models.User,{as:"Follower",through : "Follow",foreignKey:"StarID",otherKey:"followerID"});
            models.User.belongsToMany(models.User,{as:"Star",through : "Follow",foreignKey:"followerID",otherKey:"StarID"});
        }
    });
    return User;
};